package com.hhf.feiojapiservice.fallback;

import com.hhf.feiojapiservice.client.UserFeignClient;
import com.hhf.feiojcommonservice.model.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

import javax.servlet.http.HttpServletRequest;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @Author hhf
 * @Date 2024/11/3
 * @Description
 */
@Slf4j
public class UserClientFallbackFactory implements FallbackFactory<UserFeignClient>{

    @Override
    public UserFeignClient create(Throwable cause) {

        return new UserFeignClient() {
            @Override
            public User getLoginUser(HttpServletRequest request) {
                log.error("UserFeignClient getLoginUser error:{}",cause.getMessage());
                return new User();
            }

            @Override
            public User getCurrentUser() {
                log.error("UserFeignClient getCurrentUser error:{}",cause.getMessage());
                return new User();
            }

            @Override
            public List<User> listByIds(Collection<Long> idList) {
                log.error("UserFeignClient listByIds error:{}",cause.getMessage());
                return Collections.emptyList();
            }
        };
    }
}
